home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode Previous / Geometry Samples- Mac / BoxPaint+ / sources / BoxPaint_window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.8 KB  |  169 lines  |  [TEXT/CWIE]

  1. /*  window.c                                                                            
  2.  
  3.     Michael Bishop - August 21 1996                                                    
  4.     Nick Thompson
  5.     (c)1994-96 Apple computer Inc., All Rights Reserved                                
  6.  
  7. */
  8.  
  9. #include    <Devices.h>
  10.  
  11. #include    "BoxPaint_window.h"
  12. #include    "BoxPaint_document.h"
  13.  
  14. /* -------------------------------------------------------------------------------------------
  15. ** Window_New
  16. ** Kind of a dummy function at the moment.
  17. */
  18. WindowPtr Window_New(void)
  19. {
  20.     WindowPtr    tempWindow = GetNewCWindow( kWindowResID, NULL, (WindowPtr)-1L );
  21.     
  22.     return tempWindow ;
  23. }
  24.  
  25.  
  26. /* -------------------------------------------------------------------------------------------
  27. ** Window_Dispose
  28. ** Call this function when we are done with a window, deallocate any storage allocated for this,
  29. ** this gets called when we close a document.
  30. */
  31.  
  32. void Window_Dispose(WindowPtr theWindow)
  33. {
  34.  
  35.     if( theWindow != NULL )
  36.     {
  37.         DisposeWindow ( theWindow ) ;
  38.     }
  39.     
  40. }
  41.  
  42. /* -------------------------------------------------------------------------------------------
  43. ** Window_Update
  44. ** 
  45. */
  46. void Window_Update( WindowPtr theWindow )
  47. {
  48.  
  49.     CGrafPtr            savedPort ;
  50.     
  51.     if( theWindow != NULL ) 
  52.     {
  53.         DocumentHdl        myDocumentHandle = Window_GetDocument(theWindow);
  54.         Rect            updateRect = (**(theWindow->visRgn)).rgnBBox;
  55.         
  56.         if( myDocumentHandle != NULL )
  57.         {
  58.             GetPort((GrafPtr *) &savedPort );
  59.             SetPort( theWindow ) ;
  60.             
  61.             BeginUpdate( theWindow );
  62.             
  63.             HLock( (Handle)myDocumentHandle  ) ;
  64.             Document_Draw(*myDocumentHandle ) ;
  65.             HUnlock( (Handle)myDocumentHandle  ) ;
  66.             
  67.             EndUpdate( theWindow );
  68.             SetPort( (GrafPtr )savedPort ) ;
  69.         }
  70.     }
  71. }
  72.  
  73.  
  74. /* ---------------------------------------------------------------------------------- 
  75. **     Window_Activate
  76. **    is called when an theEvent is received that reports that
  77. **     a theWindow is being either activated or deactivated. 
  78. */
  79. void Window_Activate(WindowPtr theWindow, short activate)
  80. {
  81.     if (theWindow) {
  82.         if (activate) {
  83.         
  84.             /*  do whatever else you'd like to do for a activate theEvent */
  85.             /* LoadScrap() ;
  86.             */
  87.         } else {
  88.         
  89.             /*  do whatever you'd like to do for a deactivate theEvent */
  90.             /*UnloadScrap() ;
  91.             */
  92.         }
  93.     }
  94. }
  95.  
  96. /* -------------------------------------------------------------------------------------------
  97. ** Window_GetDocument
  98. ** Gets the document associated with a window
  99. */
  100.  
  101. DocumentHdl Window_GetDocument( WindowPtr theWindow)
  102. {
  103.     if (theWindow != NULL)
  104.         return    (DocumentHdl) GetWRefCon ( theWindow );
  105.     else return NULL;
  106. }
  107.  
  108. /* -------------------------------------------------------------------------------------------
  109. ** Window_SetDocument
  110. ** Gets the document associated with a window
  111. */
  112.  
  113. int Window_SetDocument( WindowPtr theWindow,  DocumentHdl theDocument)
  114. {
  115.     if (theWindow != NULL)
  116.     {
  117.         SetWRefCon (theWindow, (long)Document_GetReference(theDocument) ) ;
  118.         return    true;
  119.     }
  120.     else return false;
  121. }
  122.  
  123.  
  124.  
  125. void Window_DoContent (WindowPtr theWindow, EventRecord *theEvent)
  126. {
  127.     CGrafPtr    oldPort;
  128.     DocumentHdl    theDocument = Window_GetDocument(theWindow);
  129.     
  130.     GetPort((GrafPtr *)&oldPort);
  131.     SetPort(theWindow);
  132.     if (theEvent->modifiers & optionKey)
  133.     {
  134.         Document_Rotate(theDocument);
  135.     }    else
  136.     {
  137.         Document_DrawOnTexture(theDocument);
  138.     }
  139.     SetPort((GrafPtr)oldPort);
  140. }
  141.  
  142.  
  143. /* ---------------------------------------------------------------------------------- 
  144. **     Window_GetNextWindow
  145. **    Returns the next in the queue
  146. */
  147. WindowPtr Window_GetNextWindow(WindowPtr theWindow)
  148. {
  149.     if (theWindow != NULL)
  150.         return (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  151.     else return NULL;
  152. }
  153.  
  154. /* ---------------------------------------------------------------------------------- 
  155. **     Window_DestroyAll destroys all the windows in the app
  156. **     
  157. */
  158. void Window_DestroyAll(void)
  159. {
  160.     WindowPtr theWindow;
  161.     
  162.     theWindow = FrontWindow();                        /*    Start with the active window    */
  163.     
  164.     while (theWindow != NULL)
  165.     {
  166.         Document_Dispose( Window_GetDocument(theWindow) ) ;    /*    delete it    */
  167.         theWindow = Window_GetNextWindow(theWindow);            /*    go down the list    */
  168.     }
  169. }